package com.zx.framework.redis.config;

import java.util.EnumSet;

import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.apache.log4j.Logger;
import org.springframework.core.annotation.Order;
import org.springframework.web.WebApplicationInitializer;

@Order(3)
public class RedisSessionInitializer implements WebApplicationInitializer {
	
	private static final Logger LOGGER = Logger.getLogger(RedisSessionInitializer.class);
	@Override
	public void onStartup(ServletContext servletContext)
			throws ServletException {
		if(LOGGER.isDebugEnabled()){
			LOGGER.debug("redis session init start!");
		}
		FilterRegistration.Dynamic springSessionRepositoryFilter = servletContext.addFilter("springSessionRepositoryFilter", org.springframework.web.filter.DelegatingFilterProxy.class);
		springSessionRepositoryFilter.addMappingForUrlPatterns(  
                EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE), false, "/*");
	}
	
}
